//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<IScriptInterpreter.h>
///	@path	~/src/engine/script/
///	@date	2007/12/07
///	@desc	Script interpreter interface.

#pragma once

#include "xeres.h"

#include "lib/math/color.h"
#include "lib/utilities/string.h"

#include "database/IData.h"
#include "database/store/IFileSystem.h"

namespace xeres {

	/// Standard lex tag for lexical analysis.
	enum LexTag
	{
		LEX_EOF = 0,
		LEX_LINE ,
		LEX_SPACE ,
		LEX_TAB ,
		LEX_TEXT ,
		LEX_USER
	};

	/*!
		\struct	LexAttr
		\brief	Lexical block attribute.
	*/
	struct LexAttr
	{
		int			m_lex;
		Color3		m_color;
		WString		m_name;
	};

	/// Result of Interpreter execution.
	enum InterpretResult
	{
		INTERPRET_OK = 0 ,		// interpreter ok
		INTERPRET_STMT ,		// interpreter meets a statement which is not completed.
		INTERPRET_EMPTY ,		// interpreter meets an empty input
		INTERPRET_FAILED ,		// failed
		INTERPRET_last
	};

	/*!
		\class	IScriptInterpreter
		\brief	Script interpreter interface.
	*/
	class IScriptInterpreter : public IObject
	{
	public:

		/// \name Constructor & Destructor
		//@{

		/// @ctor
		IScriptInterpreter( void );

		/// @dtor
		virtual ~IScriptInterpreter( void );

		//@}

		DECL_IOBJECT_INTERFACE( IScriptInterpreter , IObject );

	public:

		/// \name Interpret Calls
		//@{

		/*!
			\brief		Query current prompt.
		*/
		virtual const WString& QueryPrompt( void ) =0;

		/*!
			\brief		Execute interactive script.
		*/
		virtual InterpretResult RunInteractive( const WString& script , WString& cue ) = 0;

		//@}

		/// \name Lexical Analysis Calls
		//@{

		/*!
			\brief		Begin a lex state.
		*/
		virtual void * BeginLex( const WString& str ) = 0;

		/*!
			\brief		Scan string & return its lex tag.
						Return LEX_EOF while end.
		*/
		virtual const LexAttr& NextLex( void * state , int& length ) = 0;

		/*!
			\brief		End lex state.
		*/
		virtual void EndLex( void * state ) = 0;

		//@}
	};

} // namespace xeres
